package com.hsoft.zhxy.app.demo_03_01.controller;

import com.alibaba.fastjson.JSONObject;
import com.hsoft.zhxy.app.demo_03_01.model.entity.DemoEntity;
import com.hsoft.zhxy.app.demo_03_01.service.DemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "demo_03_01 POST请求(基础增改)")
@Log4j2
@Validated
@RestController
@RequestMapping(value = "/demo_03_01/demoPost/", produces = "application/json;charset=UTF-8")
public class Demo002PostController {

    @Autowired
    DemoService demoService;

    /**
     * 新增数据 （注：本例只适用于一张数据表的新增操作，参数的校验根据DemoEntity中的配置自动完成，本例代码会自动生成，不需要编写。）
     * @param demoEntity
     * @return JSONObject
     */
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("add")
    public JSONObject add(@RequestBody @Valid DemoEntity demoEntity) {
        return demoService.add(demoEntity);
    }

    //TODO 批量新增 batchAdd

    /**
     * 修改数据 （注：本例只适用于一张数据表的修改操作，参数的校验根据DemoEntity中的配置自动完成，本例代码会自动生成，不需要编写。）
     * @param demoEntity
     * @return JSONObject
     */
    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("update")
    public JSONObject update(@RequestBody @Valid DemoEntity demoEntity) {
        return demoService.update(demoEntity);
    }

    //TODO 批量修改 batchUpdate

}
